<template>
    <div class="top">
        <div class="content">
            <!--            左侧-->
            <div class="left" @click="goHome">
                <img src="../../assets/images/logo.png" alt="">
                <p>尚医通 预约挂号统一平台</p>
            </div>

            <!--            右侧-->
            <div class="right">
                <p class="help">帮助中心</p>
                <!--                如果有用户，就显示名字-->
                <p class="login" @click="login" v-if="!useStore.userInfo.name">登录/注册</p>
                <el-dropdown v-else>
                    <span class="el-dropdown-link">
                      {{ useStore.userInfo.name }}
                      <el-icon class="el-icon--right">
                        <arrow-down/>
                      </el-icon>
                    </span>
                    <template #dropdown>
                        <el-dropdown-menu>
                            <el-dropdown-item   @click="goUser('/user/certification')">实名认证</el-dropdown-item>
                            <el-dropdown-item   @click="goUser('/user/order')">挂号订单</el-dropdown-item>
                            <el-dropdown-item   @click="goUser('/user/patient')">就诊人管理</el-dropdown-item>
                            <el-dropdown-item divided @click="signOut">退出登录</el-dropdown-item>
                        </el-dropdown-menu>
                    </template>
                </el-dropdown>
            </div>
        </div>
    </div>
</template>

<script setup lang="ts">
import {useRouter} from "vue-router";

let $router = useRouter()

import useUserStore from "@/store/modules/user.ts";
import {ArrowDown} from "@element-plus/icons-vue";

let useStore = useUserStore()
//回首页
const goHome = () => {
    $router.push({path: '/home'})
}

//点击登陆时弹框
const login = () => {
    useStore. visible = true
}
//退出登录
const signOut = ()=>{
    //通知pinia仓库清除用户信息
    useStore.signOut()
    //编程式导航跳转到首页
    $router.push({path:'/home'})
}

//跳转路由
const goUser = (path:string)=>{
    $router.push({path:path})
}
</script>


<script lang="ts">
export default {
    name: "index"
}
</script>

<style scoped lang="scss">
.top {
  position: fixed;
  z-index: 999;
  width: 100%;
  height: 70px;
  top: 0;
  background-color: #fff;
  display: flex;
  justify-content: center;

  .content {
    width: 1200px;
    height: 70px;
    background-color: white;
    display: flex;
    justify-content: space-between;

    .left {
      display: flex;
      justify-content: center;
      align-items: center;

      img {
        width: 50px;
        height: 50px;
        margin-right: 10px;
      }

      p {
        font-size: 20px;
        color: #55a6fe;
      }
    }

    .right {
      display: flex;
      justify-content: center;
      align-items: center;
      font-size: 12px;
      color: darkgray;

      .help {
        margin-right: 10px;
      }
    }
  }
}


</style>